package luogu.dfs;
//P1331 海战

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/12/21 22:54
 */
public class NavalBattle {
    static int n;
    static int m;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        sc.nextLine();
        char[][]arr=new char[n][m];
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextLine().toCharArray();
        }
        int sum=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(arr[i][j]=='#'){
                    if(dfs(i,j,arr)>0){
                        sum++;
                    }else{
                        System.out.println("Bad placement.");
                        return;
                    }
                }

            }
        }
//        for (int i = 0; i < n; i++) {
//            System.out.println(Arrays.toString(arr[i]));
//        }
        System.out.println("There are "+sum+" ships.");
    }
    public static int dfs(int x,int y,char[][]arr){
        arr[x][y]='*';
        int t=x;
        while (true){
            x++;
            if(x==n){
                break;
            }
            if(y>0&&arr[x][y-1]=='#'){
                return -1;
            }
            if(arr[x][y]=='.'||arr[x][y]=='*'){
                break;
            }
            arr[x][y]='*';
        }
        while (true){
            if(t<n-1&&arr[t+1][y]=='#'){
                return -1;
            }
            if(x>0&&arr[x-1][y]=='#'){
                return -1;
            }
            y++;
            if(y==m){
                break;
            }

            if(arr[t][y]=='.'){
                for (int i = t+1; i < x; i++) {
                    if(arr[i][y]=='#'||arr[i][y]=='*'){
                        return -1;
                    }

                }
                break;
            }if(arr[t][y]=='#'){
                for (int i = t; i < x; i++) {
                    if(arr[i][y]=='#'){
                        arr[i][y]='*';
                    }else {
                        return -1;
                    }
                }
            }

        }
        return 1;
    }
}
